/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/ce/Configuration.cpp,v 1.14 2003/11/21 12:39:24 itsme Exp $
 *
 * This module handles saving/loading of settings from the registry
 *
 *
 */

#include <windows.h>

#include "tchar.h"
#include "debug.h"
#include "PhoneOptions.h"
#include "stringutils.h"
#include "vectorutils.h"

#include "phone.h"          // for CFGTYPE constants
#include "ConfigManager.h"  // for CALLTYPE_ constants
#include "nhRegistry.h"

#define REGISTRY_PATH L"Software\\CryptoPhone"

bool LoadConfiguration()
{
    if (!GetRegistryBoolean(HKEY_CURRENT_USER, REGISTRY_PATH, L"Auto Answer",
        &g_options.auto_answer))
        g_options.auto_answer= false;
/*
    // this option is used to debug the celp voice codec,
    // by having one side only decode, and one side only encode.
    if (!GetRegistryBoolean(HKEY_CURRENT_USER, REGISTRY_PATH, L"Start Muted",
        &g_options.start_muted))
*/      g_options.start_muted= false;

    if (!GetRegistryDword(HKEY_CURRENT_USER, REGISTRY_PATH, L"Line Type",
        (DWORD*)&g_options.line_type))
    {
#ifdef _WIN32_WCE
        g_options.line_type= CFGTYPE_GSMTAPI;
#else
        g_options.line_type= CFGTYPE_DESKTOP;
#endif
    }
    if (!GetRegistryDword(HKEY_CURRENT_USER, REGISTRY_PATH, L"Modem Port",
        (DWORD*)&g_options.modem_port))
    {
        g_options.modem_port= 0;
    }
    if (!GetRegistryDword(HKEY_CURRENT_USER, REGISTRY_PATH, L"Modem Type",
        (DWORD*)&g_options.modem_type))
    {
        g_options.modem_type= K_HAYES_MODEMTYPE_POTS;
    }

    g_options.dhresend_delay= 2000;
    g_options.license_resend_delay= 15000;
    g_options.aa_state_resend_delay= 5000;

    g_options.ping_interval= 2000;
    g_options.ping_size= 8;
    g_options.call_type= ConfigManager::CALLTYPE_DIGITAL;

    if (!GetRegistryString(HKEY_CURRENT_USER, REGISTRY_PATH, L"exepath",
        g_options.exepath, MAX_PATH))
        _tcsncpy(g_options.exepath, L"CryptoPhone.exe", MAX_PATH);

    if (!GetRegistryString(HKEY_CURRENT_USER, REGISTRY_PATH, L"soundpath",
        g_options.soundpath, MAX_PATH))
        _tcsncpy(g_options.soundpath, L"Sounds", MAX_PATH);

    if (!GetRegistryString(HKEY_CURRENT_USER, REGISTRY_PATH, L"helpfile",
        g_options.helpfile, MAX_PATH))
        _tcsncpy(g_options.helpfile, L"CryptoPhone.htm", MAX_PATH);

    return true;
}
bool SaveConfiguration()
{
    return SetRegistryBoolean(HKEY_CURRENT_USER, REGISTRY_PATH, L"Auto Answer", g_options.auto_answer)
//      && SetRegistryBoolean(HKEY_CURRENT_USER, REGISTRY_PATH, L"Start Muted", g_options.start_muted)
        && SetRegistryDword(HKEY_CURRENT_USER, REGISTRY_PATH, L"Line Type", g_options.line_type)
        && SetRegistryDword(HKEY_CURRENT_USER, REGISTRY_PATH, L"Modem Port", g_options.modem_port)
        && SetRegistryDword(HKEY_CURRENT_USER, REGISTRY_PATH, L"Modem Type", g_options.modem_type);
}
